import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;


public class GameRun extends JFrame implements Runnable,KeyListener {
	Image dbImage;
	Graphics dbg;

	public GameRun(){
		setSize(500,500);
		setResizable(true);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		addKeyListener((KeyListener)this);
	}
	public void paint(Graphics g){
		dbImage = createImage(getWidth(),getHeight());
		dbg = dbImage.getGraphics();
		paintComponent(dbg);
		g.drawImage(dbImage, 0, 0, this);		
	}
	public void paintComponent(Graphics g){
		ScreenGraphics.paintScreen(g);
		ScreenGraphics.paintPlayer(g);
	}
	
	public static void main(String[] args) {
		GameRun a1 = new GameRun();
		getImages.getSpriteSheet();
		drawLevel.blank();
		
		
		Thread t1 = new Thread(a1);
		t1.start();

	}

	@Override
	public void run() {
		while(true){
			try {
				Thread.sleep(15);
				repaint();
				Player.position();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}
	@Override
	public void keyPressed(KeyEvent e) {

		if(e.getKeyCode() == 87){
			Player.move(1);
		}
		if(e.getKeyCode() == 68){
			Player.move(2);
		}
		if(e.getKeyCode() == 65){
			Player.move(3);
		}		
	}
	@Override
	public void keyReleased(KeyEvent e) {
		if(e.getKeyCode() == 87){
			Player.stop(1);
		}
		if(e.getKeyCode() == 68){
			Player.stop(2);
		}
		if(e.getKeyCode() == 65){
			Player.stop(3);
		}	
	}
	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
